package com.inews.business.wangpan.jinshan;

import java.io.File;
import java.util.Map;

import com.inews.base.mapper.JsonMapper;
import com.inews.business.vo.JinShanResultVo;

public class KuaiPanUtil {

	
	 
	public static KuaiPan getinstatice(String method){
		KuaiPan kuaipan = new KuaiPan(method);
		  kuaipan.setOauth_consumer_key("xcrno2v5MD2lnm2s");
		  kuaipan.setConsumer_secret("DKGZg1aZgTxbCYel");
		  kuaipan.setOauth_token("020365970e71718f387bc6ab");
		  kuaipan.setOauth_token_secret("6d8521d10649471ebfc411a014631856");
		  kuaipan.setOauth_signature_method("HMAC-SHA1");
		  kuaipan.setOauth_version("1.0");
		  return kuaipan;
	}

	public static Map<String,Object> account() throws Exception{
			KuaiPan kuaipan = KuaiPanUtil.getinstatice("account_info");
	 
//		   System.out.println(kuaipan.submit().get("state"));
//		  System.out.println("执行结束");
		  return kuaipan.submit();
	}

	
	public static  Map<String,Object> metadata() throws Exception{
		
		KuaiPan kuaipan = KuaiPanUtil.getinstatice("metadata");
		  kuaipan.setPath("/test");
		  kuaipan.setRoot("kuaipan");
	  kuaipan.setOauth_version("1.0");
	  Map<String,Object> result=kuaipan.submit();
	
	   
	   
	   JinShanResultVo vo= JsonMapper.nonEmptyMapper().JSONtoObject(result.get("t_result").toString(), JinShanResultVo.class);//.toJson(extData);
	
	  return result;
	}
	public static Map<String,Object> download_file(String fileName) throws Exception{
	
		KuaiPan kuaipan = KuaiPanUtil.getinstatice("download_file");
	kuaipan.setPath("/test/"+fileName);
	 kuaipan.setRoot("kuaipan");		 
	  kuaipan.setOauth_version("1.0");
	  Map<String,Object> result=kuaipan.submit();
	  
	  return result;
}

public static void main(String[] args) throws Exception {
	KuaiPanUtil.deleteFile("a.txt");

}

public static String stringToUnicode(String s) {

	String str = "";
	for (int i = 0; i < s.length(); i++) {
	int ch = (int) s.charAt(i);
	str += "\\u" + Integer.toHexString(ch);
	}
	return str;

	}

public static  Map<String,Object> upload_file(File uploadFile,String fileName) throws Exception{
	KuaiPan kuaipan = KuaiPanUtil.getinstatice("upload_file");
	kuaipan.setOverwrite(true);
	kuaipan.setPath("/test/"+fileName);
	kuaipan.setRoot("kuaipan");
	kuaipan.setLocal_file(uploadFile);
	Map<String,Object> map = kuaipan.submit();
	System.out.println(map.get("state"));
	return map;
}


public static  Map<String,Object> deleteFile(String fileName) throws Exception{
	KuaiPan kuaipan = KuaiPanUtil.getinstatice("delete");
	
	kuaipan.setPath("/test/"+fileName);
	kuaipan.setRoot("kuaipan");
	Map<String,Object> map = kuaipan.submit();
	System.out.println(map.get("state"));
	return map;
}


}



